package javaDemo;

import java.io.*;

public class FileDemo {

   /* public static void main(String[] args) {
        File src =new File("G:\\");
        getPath(src);
    }

    public static void getPath(File file){
        File[] files =file.listFiles();
        if(files !=null){
            for (File f :files){
                if (f.isDirectory()){//规则
                    getPath(f);
                }else {//出口
                   System.out.println(f.getAbsolutePath());
                }
            }
        }

    }*/

    /*public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("G:\\lqx.jpg");
        FileOutputStream fos = new FileOutputStream("G:\\workspaces\\JavaStudy\\test.jpg");
        byte[] bytes = new byte[1024];
        int len;
        while ((len = fis.read(bytes)) !=-1){
            fos.write(bytes,0,len);
        }
        fis.close();
        fos.close();
    }*/

    public static void main(String[] args) throws IOException{
        long startTime = System.currentTimeMillis();

       // method01();//耗时:72348
        //method02();//耗时:141
       // method03();//耗时:671
        //method04();//耗时：59
       // method05();
        method06();
        long endTime = System.currentTimeMillis();
        System.out.println("耗时："+(endTime-startTime));
    }

    //一次读取一个字节
    public static void method01() throws IOException {
        FileInputStream fis = new FileInputStream("G:\\JAVA\\第二阶段视频\\day9\\15_IO流小结.mp4");
        FileOutputStream fos = new FileOutputStream("G:\\workspaces\\JavaStudy\\01.mp4");

        int by;
        while ((by=fis.read()) !=-1){
            fos.write(by);
        }
        fis.close();
        fos.close();

    }

    //一次读取一个字节数据
    public static void method02() throws IOException {
        FileInputStream fis = new FileInputStream("G:\\JAVA\\第二阶段视频\\day9\\15_IO流小结.mp4");
        FileOutputStream fos = new FileOutputStream("G:\\workspaces\\JavaStudy\\01.mp4");

        byte[] bytes = new byte[1024];
        int len;
        while ((len=fis.read(bytes))!=-1){
            fos.write(bytes);
        }

        fis.close();
        fos.close();

    }

    //
    public static void method03() throws IOException {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("G:\\JAVA\\第二阶段视频\\day9\\15_IO流小结.mp4"));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("G:\\workspaces\\JavaStudy\\01.mp4"));
        int by;
        while ((by=bufferedInputStream.read()) !=-1){
            bufferedOutputStream.write(by);
        }
        bufferedInputStream.close();
        bufferedOutputStream.close();
    }

    public static void method04() throws IOException {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("G:\\JAVA\\第二阶段视频\\day9\\15_IO流小结.mp4"));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("G:\\workspaces\\JavaStudy\\01.mp4"));
        byte[] bytes = new byte[1024];
        int len;
        while ((len=bufferedInputStream.read(bytes))!=-1){
            bufferedOutputStream.write(bytes);
        }


        bufferedInputStream.close();
        bufferedOutputStream.close();
    }

    public static void method05() throws IOException {
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream("G:\\workspaces\\JavaStudy\\o.txt"));
        outputStreamWriter.write(97);
        outputStreamWriter.close();
    }

    public static void method06() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader("G:\\workspaces\\JavaStudy\\o.txt"));

       BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("G:\\workspaces\\JavaStudy\\o1.txt"));

       /* char[] chars = new char[1024];
        int len;
        while ((len = bufferedReader.read(chars))!=-1){
            bufferedWriter.write(chars,0,len);
        }*/

        String s;
        while ((s=bufferedReader.readLine())!=null){
            bufferedWriter.write(s);
        }


      /* int cc ;
       while ((cc=bufferedReader.read())!=-1){
           System.out.println(cc);
       }
        bufferedReader.close();*/

        bufferedReader.close();
        bufferedWriter.close();
    }



}
